public class Zcsh {
    public int maxScore(int[] cardPoints, int k) {
        int max = 0;
        for (int i = 0; i < k; i++) {
            max += cardPoints[i];
        }

        int currentValue = max;
        for (int i = k - 1, j = cardPoints.length - 1; i >= 0; i--, j--) {
            currentValue = currentValue - cardPoints[i] + cardPoints[j];
            max = Math.max(max, currentValue);
        }

        return max;
    }
}